package 区间分组;

import java.util.*;

public class Main {
    static int N = 100010;
    static PII[] g = new PII[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            int l = in.nextInt();
            int r = in.nextInt();
            g[i] = new PII(l, r);
        }
        Arrays.sort(g, 0, n);
        PriorityQueue<Integer> q = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            if (q.isEmpty() || q.peek() >= g[i].l) {
                q.offer(g[i].r);
            } else {
                q.poll();
                q.offer(g[i].r);
            }
        }
        System.out.println(q.size());
    }

}

class PII implements Comparable<PII> {
    int l, r;

    public PII(int l, int r) {
        this.l = l;
        this.r = r;
    }

    @Override
    public int compareTo(PII o) {
        return Integer.compare(this.l, o.l);
    }
}